package object;

import java.util.Arrays;

public class MyPriorityQueue {
    public int[] arr;
    public int size;

    public MyPriorityQueue() {
        arr = new int[10];
    }
    public void revise() {
        int[] newArr = new int[arr.length + (arr.length >> 1)];
        for (int i=0 ;i<arr.length ;i++) {
            newArr[i] = arr[i];
        }
        arr = newArr;
    }
    public void offer(int elem) {
        if (size >= arr.length) {
            revise();
        }
        arr[size] = elem;
        size++;
        Test.shiftUp(arr,size - 1);
    }
    public Integer poll() {
        int tmp = arr[0];
        arr[0] = arr[size - 1];
        arr[size - 1] = arr[0];
        size--;
        Test.shiftDown(arr,size,0);
        return tmp;
    }
    public Integer peek() {
        if (size == 0) {
            return null;
        }
        return arr[0];
    }



    @Override
    public String toString() {
        return "MyPriorityQueue{" +
                "arr=" + Arrays.toString(arr) +
                ", size=" + size +
                '}';
    }

    public static void main(String[] args) {
        MyPriorityQueue myPriorityQueue = new MyPriorityQueue();
        myPriorityQueue.offer(4);
        myPriorityQueue.offer(3);
        myPriorityQueue.offer(2);
        myPriorityQueue.offer(1);
        System.out.println(myPriorityQueue);
        System.out.println(myPriorityQueue.poll());
        System.out.println(myPriorityQueue.poll());
        System.out.println(myPriorityQueue.peek());

    }



}
